package com.kos.snakerunningsystem.controller;

import com.kos.snakerunningsystem.service.SnakeRunningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
public class SnakeRunningController {

    @Autowired
    private SnakeRunningService snakeRunningService;

    @RequestMapping("/snake/add")
    public String addSnake(@RequestParam MultiValueMap<String,String> data){
        Integer userId = Integer.parseInt(Objects.requireNonNull(data.getFirst("user_id")));
        String snakeCode = data.getFirst("snake_code");
        String input = data.getFirst("input");
        return snakeRunningService.addSnake(userId,snakeCode,input);
    }
}
